﻿using HZY.Framework.DependencyInjection;
using Long.DAL;
using Long.Helper;
using Long.Model;
using Mapster;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Security.Cryptography.Xml;
using System.Text;
using System.Threading.Tasks;

namespace Long.BLL
{
    public class AuthManager : IScopedSelfDependency
    {
        public readonly AuthService _authService;

        public AuthManager(AuthService authService)
        {
            _authService = authService;
        }
        //默认4种角色拥有的操作权限：改、查、校对

        public async Task<BaseResult> UpdateAuthAsyncManager(AuthUpdateDto request)
        {
            AuthEntity resentity = request.Adapt<AuthEntity>();
            bool res = await _authService.UpdateAsync(resentity);
            if (res)
            {
                return new BaseResult() { ResultStatus = SystemEnums.ResultStatus.Success };
            }
            return new BaseResult() { ResultStatus = SystemEnums.ResultStatus.Fail,Msg = $"{request.Role}权限修改失败" };
        } 

        public async Task<BaseResult<AuthQueryRequestDto>> QueryAuthAsyncManager(AuthQueryDto request)
        {
            List<AuthEntity> entity = await _authService.GetByListAsync(e => e.Role == request.Role);
            List<AuthQueryRequestDto> res = entity.Adapt<List<AuthQueryRequestDto>>();
            return new BaseResult<AuthQueryRequestDto>() { ResultStatus = SystemEnums.ResultStatus.Success, Data = res };
        }
        public async Task<BaseResult<AuthRequestDto>> GetAuthAsync(AuthQueryDto request)
        {
            List<AuthEntity> entity = await _authService.GetByListAsync(e => e.Role == request.Role);
            List<AuthRequestDto> res = entity.Adapt<List<AuthRequestDto>>();
            return new BaseResult<AuthRequestDto>() { ResultStatus = SystemEnums.ResultStatus.Success, Data = res };
        }
    }
}
